home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / BARNET / FREENET / BRODIE / INTERNET / !InternetD / c / daytime < prev    next >
Text File  |  1995-06-07  |  1KB  |  52 lines

  1. #include "inetd.h"
  2. #include "oslib:h.osword"
  3. #include "oslib:h.territory"
  4.  
  5. #define DAYTIMESIZE    64
  6. #define DAYTIMEFORMAT    "%W3 %M3 %DY %24:%MI:%SE %CE%YR"
  7.  
  8. static char *daytime_prepare(char *timebuff)
  9. {
  10.     oswordreadclock_utc_block utc = { oswordreadclock_OP_UTC } ;
  11.     char        *end;
  12.  
  13.     xoswordreadclock_utc(&utc);
  14.     xterritory_convert_date_and_time(-1, &utc.utc, timebuff,
  15.         DAYTIMESIZE, DAYTIMEFORMAT, &end);
  16.     *end++ = '\r';
  17.     *end++ = '\n';
  18.     *end = 0;
  19.  
  20.     return timebuff;
  21. }
  22.  
  23. void daytime_tcp(int s)
  24. {
  25.     char            timebuff[DAYTIMESIZE];
  26.         int             t;
  27.         struct sockaddr_in    address;
  28.     int            size = sizeof(struct sockaddr_in);
  29.     char            *date;
  30.  
  31.         t = accept(s, (struct sockaddr *)&address, &size);
  32.         if (t == -1) return;
  33.     date = daytime_prepare(timebuff);
  34.     ioctl(t, FIONBIO, 1);
  35.     send(t, date, strlen(date), 0);
  36.     kill_socket(&t);
  37. }
  38.  
  39. void daytime_udp(int s)
  40. {
  41.         struct    sockaddr_in    address;
  42.         int    size        = sizeof(struct sockaddr_in);
  43.         char            *date;
  44.     char            timebuff[DAYTIMESIZE];
  45.  
  46.     if (recvfrom(s, timebuff, DAYTIMESIZE, 0,
  47.         (struct sockaddr *)&address, &size) == -1) return;
  48.  
  49.     date = daytime_prepare(timebuff);
  50.     sendto(s, date, strlen(date), 0, (struct sockaddr *)&address, size);
  51. }
  52.